<div class="box">
  <div class="box-header ">
    
    <ob_link><a class="btn" href="{:url('groupAdd')}"><i class="fa fa-plus"></i> 新 增</a></ob_link>
    &nbsp;
    <ob_link><a class="btn export" url="{:url('exportGroupList')}"><i class="fa fa-download"></i> 导 出</a></ob_link>
    
    <div class="box-header ajax-form searchAll">
    <div class="col-md-3 col-sm-3 col-3">
        <label>组名<input type="text" name="group_name" value="{:input('group_name')}" class="form-control form-control-sm ajax-form-value" placeholder="请输入组名" ></label>
    </div>
    <div class="col-md-3 col-sm-3 col-3">
        <label>公司名<select class="form-control form-control-sm ajax-form-value" name="company_id" id="company_list">
          <option value="">请选择公司名</option>
          {volist name='company_list' id='vo'}
              <option value="{$vo['id']}" {if input('company_id') == $vo['id']} selected="selected" {/if} >{$vo['name']}</option>
          {/volist}
        </select></label>
    </div>
    <div class="col-md-3 col-sm-3 col-3">
        <label>部门名<select class="form-control form-control-sm ajax-form-value" name="branch_id" id="branch_list">
          <option value="">请选择部门名</option>
          {volist name='branch_list' id='vo'}
              <option value="{$vo['id']}" {if input('branch_id') == $vo['id']} selected="selected" {/if} >{$vo['branch_name']}</option>
          {/volist}
        </select></label>
    </div>
    <div class="col-md-1 col-sm-1 col-1">
        <div class="btn-group pull-right" style="margin-top:20px;margin-right:20px">
            <a href="javascript:;" id="searchAll" class="btn btn-default"  url="{:url('groupList')}">
                搜索<i class="fa fa-search"></i>
            </a>
        </div>
    </div>
    <div class="col-md-1 col-sm-1 col-1">
        <div class="btn-group pull-right" style="margin-top:20px;margin-right:20px">
            <a href="javascript:;" id="searchclear" class="btn btn-default">
                重置<i class="fa fa-history"></i>
            </a>
        </div>
    </div>
  </div>
    <br/>
  </div>
    
  <div class="box-body table-responsive">
    <table  class="table table-bordered table-hover">
      <thead>
      <tr>
          <th>组名称</th>
          <th>组负责人</th>
          <th>所属部门</th>
          <th>所属公司</th>
          <th>组人数</th>
          <th>注册时间</th>
          <th>排序</th>
          <th>状态</th>
          <th>操作</th>
      </tr>
      </thead>
      
      {notempty name='list'}
        <tbody>
            {volist name='list' id='vo'}
                <tr>
                  <td>{$vo.group_name}</td>
                  <td>{$vo.principal}</td>
                  <td>{$vo.branch_name}</td>
                  <td>{$vo.name}</td>
                  <td>{$vo.num}</td>
                  <td>{$vo.create_time}</td>
                  <td>{$vo.sort}</td>
                  <td>{$vo.status_text}</td>
                  <td class="col-md-3 text-center">
                      <ob_link><a href="{:url('groupEdit', array('id' => $vo['id']))}" class="btn"><i class="fa fa-edit"></i> 编 辑</a></ob_link>
                      &nbsp;
                      <ob_link><a class="btn confirm ajax-get"  href="{:url('groupDel', array('id' => $vo['id']))}"><i class="fa fa-trash-o"></i> 删 除</a></ob_link>
                  </td>
                </tr>
            {/volist}
        </tbody>
        {else/}
        <tbody><tr class="odd"><td colspan="8" class="text-center" valign="top">{:config('empty_list_describe')}</td></tr></tbody>
      {/notempty}
    </table>
  </div>

  <div class="box-footer clearfix text-center">
      {$list->render()}
  </div>

</div>

<script>
   $('#company_list').change(function(){
    var options=$(this).children("option:selected");
     // options.attr('selected','selected'); 
    var company_id=options.val();
    $('#branch_list option').remove();
    $('#group_list option').remove();
     $("#group_list").append("<option value=''>请选择组</option>");
     $("#branch_list").append("<option value=''>请选择部门</option>");
    $.post('/admin/branch/branchlist',{company_id:company_id},function(data){
      $(data.data).each(function(index,item){ 
          var option="<option value="+item.id+">"+item.branch_name+"</option>"
          $("#branch_list").append(option);  
            // console.log(item); 
        }); 
    });  
  })

  $('#branch_list').change(function(){
    var options=$(this).children("option:selected");
     options.attr('selected','selected'); 
    var branch_id=options.val();
    $('#group_list option').remove();
     $("#group_list").append("<option value=''>请选择组</option>");
    // alert(branch_id);
    $.post('/admin/group/grouplist',{branch_id:branch_id},function(data){
      $(data.data).each(function(index,item){ 
          var option="<option value="+item.id+">"+item.group_name+"</option>"
          $("#group_list").append(option);  
            console.log(item); 
        }); 
    });  
  })
    //搜索条件重置
    $('#searchclear').click(function(){
      $('.form-control').val('');
    })
    //导出功能
    $(".export").click(function(){
        
        window.location.href = searchAllFormUrl($(".export"));
    });
</script>